package com.bigflexlib.ds.container.zet.impl
{
	import com.bigflexlib.ds.DataStructureEvent;
	import com.bigflexlib.ds.container.ContainerDiff;
	import com.bigflexlib.ds.container.utils.MultiplicityChange;
	import com.bigflexlib.ds.container.zet.IOWSet;
	import com.bigflexlib.utils.BasicTestBase;


	/**
	 * 
	 * @private
	 * 
	 */
	public class OWSetWrapperTest extends BasicTestBase
	{



		private var currentTest:int = 0;


		public function test_events( ):void
		{
		
			
			var s1:IOWSet = owSet( );
			
			s1.addEventListener( DataStructureEvent.CHANGE, verifyEvent );
			

		currentTest = 0;

			s1.add( "a" );
			
			
		currentTest = 1;

			s1.remove( "a" );
			

		currentTest = 2;
		
			s1.autoUpdateFlag.disable( );
			
			s1.add( "a" );
			s1.add( "b" );
			s1.add( "c" );
			s1.remove( "c" );

			s1.autoUpdateFlag.enable( );
			
			
		currentTest = 3;
		
			s1.clear( );
					
		
		}
		
		
		
		private function verifyEvent( event:DataStructureEvent ):void
		{
			
			var diff:ContainerDiff = event.diff as ContainerDiff;
			var mc_0_1:MultiplicityChange = new MultiplicityChange( 0, 1 );
			var mc_1_0:MultiplicityChange = new MultiplicityChange( 1, 0 );
		
			
			switch ( currentTest )
			{
				
				case 0: // added a
					
					assertEquals( diff.addedElements.size, 1 );				
					assertEquals( diff.removedElements.size, 0 );				
					assertTrue( diff.addedElements.compare( owSet( ["a"] ) ).isEqual );
					assertTrue( mc_0_1.compare( diff.multiplicityChanges["a"] ).isEqual );
				
				break;
			

			
				case 1: // removed a
				
					assertEquals( diff.addedElements.size, 0 );				
					assertEquals( diff.removedElements.size, 1 );
					assertTrue( diff.removedElements.compare( owSet( ["a"] ) ).isEqual );
					assertTrue( mc_1_0.compare( diff.multiplicityChanges["a"] ).isEqual );
				
				break;
			


				case 2: // added a, b, c... removed c
				
					assertEquals( diff.addedElements.size, 2 );				
					assertEquals( diff.removedElements.size, 0 );
					assertTrue( diff.addedElements.compare( owSet( [ "a", "b" ] ) ).isEqual );
					
					assertTrue( mc_0_1.compare( diff.multiplicityChanges["a"] ).isEqual );
					assertTrue( mc_0_1.compare( diff.multiplicityChanges["b"] ).isEqual );
				
				break;
			
				case 3: // clear ( removed a, b )
				
					assertEquals( diff.addedElements.size, 0 );				
					assertEquals( diff.removedElements.size, 2 );
					assertTrue( diff.removedElements.compare( owSet( [ "a", "b" ] ) ).isEqual );
					
					assertTrue( mc_1_0.compare( diff.multiplicityChanges["a"] ).isEqual );
					assertTrue( mc_1_0.compare( diff.multiplicityChanges["b"] ).isEqual );
				
				break;
			
			
			
			}
			
			
		
		
		}


		
	}
}